package SOSO;

import java.util.Set;

public class UseSoso {
    public void use(String number) {
        boolean index = false;
        Set<String> set = Test.mobileCards.keySet();
        for (String s : set) {
            if (s.equals(number)) {
                index = true;
                if (Test.mobileCards.get(s).getSerPackage() instanceof SuperPackage) {
                    switch ((int) (Math.random() * 6)) {
                        case 0:
                            for (int i = 1; i <= 90; i++) {
                                int temp = i;
                                if (((SuperPackage) Test.mobileCards.get(s).getSerPackage()).getTalkTime() - Test.mobileCards.get(s).getRealTalkTime() >= 1) {
                                    Test.mobileCards.get(s).setRealTalkTime(Test.mobileCards.get(s).getRealTalkTime() + 1);
                                } else if (Test.mobileCards.get(s).getMoney() > 0.3) {
                                    Test.mobileCards.get(s).setRealTalkTime(Test.mobileCards.get(s).getRealTalkTime() + 1);
                                    Test.mobileCards.get(s).setMoney(Test.mobileCards.get(s).getMoney() - 0.2);
                                    Test.mobileCards.get(s).setConsumAmount(Test.mobileCards.get(s).getConsumAmount() + 0.2);
                                } else {
                                    System.out.println("此次使用了" + (i - 1) + "分钟，继续使用请充值");
                                    if(i-1>0){
                                        Test.consumInfoList.add(new ConsumInfo(number, "通话", i - 1));
                                        Test.consumInfos.put(number, Test.consumInfoList);
                                    }else {
                                        try {
                                            throw new Exception();
                                        } catch (Exception e) {
                                            System.out.println("请先充值后使用！");
                                        }
                                    }
                                    break;
                                }
                                if (i == 90) {
                                    Test.consumInfoList.add(new ConsumInfo(number, "通话", 90));
                                    Test.consumInfos.put(number, Test.consumInfoList);
                                    System.out.println("问候客户，谁知其如此难缠，通话用时90分钟。");
                                }
                            }
                            break;
                        case 1:
                            for (int i = 1; i <= 30; i++) {
                                int temp = i;
                                if (((SuperPackage) Test.mobileCards.get(s).getSerPackage()).getTalkTime() - Test.mobileCards.get(s).getRealTalkTime() >= 1) {
                                    Test.mobileCards.get(s).setRealTalkTime(Test.mobileCards.get(s).getRealTalkTime() + 1);
                                } else if (Test.mobileCards.get(s).getMoney() > 0.3) {
                                    Test.mobileCards.get(s).setRealTalkTime(Test.mobileCards.get(s).getRealTalkTime() + 1);
                                    Test.mobileCards.get(s).setMoney(Test.mobileCards.get(s).getMoney() - 0.2);
                                    Test.mobileCards.get(s).setConsumAmount(Test.mobileCards.get(s).getConsumAmount() + 0.2);
                                } else {
                                    System.out.println("此次使用了" + (i - 1) + "分钟，继续使用请充值");
                                    if(i-1>0){
                                        Test.consumInfoList.add(new ConsumInfo(number, "通话", i - 1));
                                        Test.consumInfos.put(number, Test.consumInfoList);
                                    }else {
                                        try {
                                            throw new Exception();
                                        } catch (Exception e) {
                                            System.out.println("请先充值后使用！");
                                        }
                                    }
                                    break;
                                }
                                if (i == 30) {
                                    Test.consumInfoList.add(new ConsumInfo(number, "通话", 30));
                                    Test.consumInfos.put(number, Test.consumInfoList);
                                    System.out.println("和母亲通话用时90分钟。");
                                }
                            }
                            break;

                        case 2:
                            for (int i = 1; i <= 5; i++) {
                                int temp = i;
                                if (((SuperPackage) Test.mobileCards.get(s).getSerPackage()).getSmsCount() - Test.mobileCards.get(s).getRealSMSCount() >= 1) {
                                    Test.mobileCards.get(s).setRealSMSCount(Test.mobileCards.get(s).getRealSMSCount() + 1);
                                } else if (Test.mobileCards.get(s).getMoney() > 0.2) {
                                    Test.mobileCards.get(s).setRealSMSCount(Test.mobileCards.get(s).getRealSMSCount() + 1);
                                    Test.mobileCards.get(s).setMoney(Test.mobileCards.get(s).getMoney() - 0.1);
                                    Test.mobileCards.get(s).setConsumAmount(Test.mobileCards.get(s).getConsumAmount() + 0.1);
                                } else {
                                    System.out.println("此次使用了" + (i - 1) + "条短信，继续使用请充值");
                                    if(i-1>0){
                                        Test.consumInfoList.add(new ConsumInfo(number, "短信", i - 1));
                                        Test.consumInfos.put(number, Test.consumInfoList);
                                    }else {
                                        try {
                                            throw new Exception();
                                        } catch (Exception e) {
                                            System.out.println("请先充值后使用！");
                                        }
                                    }
                                    break;
                                }
                                if (i == 5) {
                                    Test.consumInfoList.add(new ConsumInfo(number, "短信", 5));
                                    Test.consumInfos.put(number, Test.consumInfoList);
                                    System.out.println("为环保做宣传发了5条短信。");
                                }
                            }
                            break;

                        case 3:
                            for (int i = 1; i <= 50; i++) {
                                int temp = i;
                                if (((SuperPackage) Test.mobileCards.get(s).getSerPackage()).getSmsCount() - Test.mobileCards.get(s).getRealSMSCount() >= 1) {
                                    Test.mobileCards.get(s).setRealSMSCount(Test.mobileCards.get(s).getRealSMSCount() + 1);
                                } else if (Test.mobileCards.get(s).getMoney() > 0.2) {
                                    Test.mobileCards.get(s).setRealSMSCount(Test.mobileCards.get(s).getRealSMSCount() + 1);
                                    Test.mobileCards.get(s).setMoney(Test.mobileCards.get(s).getMoney() - 0.1);
                                    Test.mobileCards.get(s).setConsumAmount(Test.mobileCards.get(s).getConsumAmount() + 0.1);
                                } else {
                                    System.out.println("此次使用了" + (i - 1) + "条短信，继续使用请充值");
                                    if(i-1>0){
                                        Test.consumInfoList.add(new ConsumInfo(number, "短信", i - 1));
                                        Test.consumInfos.put(number, Test.consumInfoList);
                                    }else {
                                        try {
                                            throw new Exception();
                                        } catch (Exception e) {
                                            System.out.println("请先充值后使用！");
                                        }
                                    }
                                    break;
                                }
                                if (i == 50) {
                                    Test.consumInfoList.add(new ConsumInfo(number, "短信", 50));
                                    Test.consumInfos.put(number, Test.consumInfoList);
                                    System.out.println("给朋友发祝福，发了50条短信。");
                                }
                            }
                            break;
                        case 4:
                            for (int i = 1; i <= 1024; i++) {
                                int temp = i;
                                if (((SuperPackage) Test.mobileCards.get(s).getSerPackage()).getFlow() - Test.mobileCards.get(s).getRealFlow() >= 1) {
                                    Test.mobileCards.get(s).setRealFlow(Test.mobileCards.get(s).getRealFlow() + 1);
                                } else if (Test.mobileCards.get(s).getMoney() > 0.2) {
                                    Test.mobileCards.get(s).setRealFlow(Test.mobileCards.get(s).getRealFlow() + 1);
                                    Test.mobileCards.get(s).setMoney(Test.mobileCards.get(s).getMoney() - 0.1);
                                    Test.mobileCards.get(s).setConsumAmount(Test.mobileCards.get(s).getConsumAmount() + 0.1);
                                } else {
                                    System.out.println("此次使用了" + (i - 1) + "MB流量，继续使用请充值");
                                    if(i-1>0){
                                        Test.consumInfoList.add(new ConsumInfo(number, "上网", i - 1));
                                        Test.consumInfos.put(number, Test.consumInfoList);
                                    }else {
                                        try {
                                            throw new Exception();
                                        } catch (Exception e) {
                                            System.out.println("请先充值后使用！");
                                        }
                                    }
                                    break;
                                }
                                if (i == 1024) {
                                    Test.consumInfoList.add(new ConsumInfo(number, "上网", 1024));
                                    Test.consumInfos.put(number, Test.consumInfoList);
                                    System.out.println("和女朋友视频用了1GB流量。");
                                }
                            }
                            break;
                        case 5:
                            for (int i = 1; i <= 2048; i++) {
                                int temp = i;
                                if (((SuperPackage) Test.mobileCards.get(s).getSerPackage()).getFlow() - Test.mobileCards.get(s).getRealFlow() >= 1) {
                                    Test.mobileCards.get(s).setRealFlow(Test.mobileCards.get(s).getRealFlow() + 1);
                                } else if (Test.mobileCards.get(s).getMoney() > 0.2) {
                                    Test.mobileCards.get(s).setRealFlow(Test.mobileCards.get(s).getRealFlow() + 1);
                                    Test.mobileCards.get(s).setMoney(Test.mobileCards.get(s).getMoney() - 0.1);
                                    Test.mobileCards.get(s).setConsumAmount(Test.mobileCards.get(s).getConsumAmount() + 0.1);
                                } else {
                                    System.out.println("此次使用了" + (i - 1) + "MB流量，继续使用请充值");
                                    if(i-1>0){
                                        Test.consumInfoList.add(new ConsumInfo(number, "上网", i - 1));
                                        Test.consumInfos.put(number, Test.consumInfoList);
                                    }else {
                                        try {
                                            throw new Exception();
                                        } catch (Exception e) {
                                            System.out.println("请先充值后使用！");
                                        }
                                    }
                                    break;
                                }
                                if (i == 2048) {
                                    Test.consumInfoList.add(new ConsumInfo(number, "上网", 2048));
                                    Test.consumInfos.put(number, Test.consumInfoList);
                                    System.out.println("看视频，不小心睡着，用了2GB流量。");
                                }
                            }
                            break;
                    }
                } else if (Test.mobileCards.get(s).getSerPackage() instanceof TalkPackage) {
                    boolean index2 = false;
                    switch ((int) (Math.random() * 4)) {
                        case 0:
                            for (int i = 1; i <= 90; i++) {
                                int temp = i;
                                if (((TalkPackage) Test.mobileCards.get(s).getSerPackage()).getTalkTime() - Test.mobileCards.get(s).getRealTalkTime() >= 1) {
                                    Test.mobileCards.get(s).setRealTalkTime(Test.mobileCards.get(s).getRealTalkTime() + 1);
                                } else if (Test.mobileCards.get(s).getMoney() > 0.3) {
                                    Test.mobileCards.get(s).setRealTalkTime(Test.mobileCards.get(s).getRealTalkTime() + 1);
                                    Test.mobileCards.get(s).setMoney(Test.mobileCards.get(s).getMoney() - 0.2);
                                    Test.mobileCards.get(s).setConsumAmount(Test.mobileCards.get(s).getConsumAmount() + 0.2);
                                } else {
                                    System.out.println("此次使用了" + (i - 1) + "分钟，继续使用请充值");
                                    if(i-1>0){
                                        Test.consumInfoList.add(new ConsumInfo(number, "通话", i - 1));
                                        Test.consumInfos.put(number, Test.consumInfoList);
                                    }else {
                                        try {
                                            throw new Exception();
                                        } catch (Exception e) {
                                            System.out.println("请先充值后使用！");
                                        }
                                    }
                                    break;
                                }
                                if (i == 90) {
                                    Test.consumInfoList.add(new ConsumInfo(number, "通话", 90));
                                    Test.consumInfos.put(number, Test.consumInfoList);
                                    System.out.println("问候客户，谁知其如此难缠，通话用时90分钟。");
                                }
                            }
                            break;
                        case 1:
                            for (int i = 1; i <= 30; i++) {
                                int temp = i;
                                if (((TalkPackage) Test.mobileCards.get(s).getSerPackage()).getTalkTime() - Test.mobileCards.get(s).getRealTalkTime() >= 1) {
                                    Test.mobileCards.get(s).setRealTalkTime(Test.mobileCards.get(s).getRealTalkTime() + 1);
                                } else if (Test.mobileCards.get(s).getMoney() > 0.3) {
                                    Test.mobileCards.get(s).setRealTalkTime(Test.mobileCards.get(s).getRealTalkTime() + 1);
                                    Test.mobileCards.get(s).setMoney(Test.mobileCards.get(s).getMoney() - 0.2);
                                    Test.mobileCards.get(s).setConsumAmount(Test.mobileCards.get(s).getConsumAmount() + 0.2);
                                } else {
                                    System.out.println("此次使用了" + (i - 1) + "分钟，继续使用请充值");
                                    if(i-1>0){
                                        Test.consumInfoList.add(new ConsumInfo(number, "通话", i - 1));
                                        Test.consumInfos.put(number, Test.consumInfoList);
                                    }else {
                                        try {
                                            throw new Exception();
                                        } catch (Exception e) {
                                            System.out.println("请先充值后使用！");
                                        }
                                    }
                                    break;
                                }
                                if (i == 30) {
                                    Test.consumInfoList.add(new ConsumInfo(number, "通话", 30));
                                    Test.consumInfos.put(number, Test.consumInfoList);
                                    System.out.println("和母亲通话用时30分钟。");
                                }
                            }
                            break;
                        case 2:
                            for (int i = 1; i <= 5; i++) {
                                int temp = i;
                                if (((TalkPackage) Test.mobileCards.get(s).getSerPackage()).getSmsCount() - Test.mobileCards.get(s).getRealSMSCount() >= 1) {
                                    Test.mobileCards.get(s).setRealSMSCount(Test.mobileCards.get(s).getRealSMSCount() + 1);
                                } else if (Test.mobileCards.get(s).getMoney() > 0.2) {
                                    Test.mobileCards.get(s).setRealSMSCount(Test.mobileCards.get(s).getRealSMSCount() + 1);
                                    Test.mobileCards.get(s).setMoney(Test.mobileCards.get(s).getMoney() - 0.1);
                                    Test.mobileCards.get(s).setConsumAmount(Test.mobileCards.get(s).getConsumAmount() + 0.1);
                                } else {
                                    System.out.println("此次使用了" + (i - 1) + "条短信，继续使用请充值");
                                    if(i-1>0){
                                        Test.consumInfoList.add(new ConsumInfo(number, "短信", i - 1));
                                        Test.consumInfos.put(number, Test.consumInfoList);
                                    }else {
                                        try {
                                            throw new Exception();
                                        } catch (Exception e) {
                                            System.out.println("请先充值后使用！");
                                        }
                                    }
                                    break;
                                }
                                if (i == 5) {
                                    Test.consumInfoList.add(new ConsumInfo(number, "短信", 5));
                                    Test.consumInfos.put(number, Test.consumInfoList);
                                    System.out.println("为环保做宣传发了5条短信。");
                                }
                            }
                            break;
                        case 3:
                            for (int i = 1; i <= 50; i++) {
                                int temp = i;
                                if (((TalkPackage) Test.mobileCards.get(s).getSerPackage()).getSmsCount() - Test.mobileCards.get(s).getRealSMSCount() >= 1) {
                                    Test.mobileCards.get(s).setRealSMSCount(Test.mobileCards.get(s).getRealSMSCount() + 1);
                                } else if (Test.mobileCards.get(s).getMoney() > 0.2) {
                                    Test.mobileCards.get(s).setRealSMSCount(Test.mobileCards.get(s).getRealSMSCount() + 1);
                                    Test.mobileCards.get(s).setMoney(Test.mobileCards.get(s).getMoney() - 0.1);
                                    Test.mobileCards.get(s).setConsumAmount(Test.mobileCards.get(s).getConsumAmount() + 0.1);
                                } else {
                                    System.out.println("此次使用了" + (i - 1) + "条短信，继续使用请充值");
                                    if(i-1>0){
                                        Test.consumInfoList.add(new ConsumInfo(number, "短信", i - 1));
                                        Test.consumInfos.put(number, Test.consumInfoList);
                                    }else {
                                        try {
                                            throw new Exception();
                                        } catch (Exception e) {
                                            System.out.println("请先充值后使用！");
                                        }
                                    }
                                    break;
                                }
                                if (i == 50) {
                                    Test.consumInfoList.add(new ConsumInfo(number, "短信", 50));
                                    Test.consumInfos.put(number, Test.consumInfoList);
                                    System.out.println("给朋友发祝福，发了50条短信。");
                                }
                            }
                            break;
                    }
                } else if (Test.mobileCards.get(s).getSerPackage() instanceof NetPackage) {
                    switch ((int) (Math.random() * 2)) {
                        case 0:
                            for (int i = 1; i <= 1024; i++) {
                                int temp = i;
                                if (((NetPackage) Test.mobileCards.get(s).getSerPackage()).getFlow() - Test.mobileCards.get(s).getRealFlow() >= 1) {
                                    Test.mobileCards.get(s).setRealFlow(Test.mobileCards.get(s).getRealFlow() + 1);
                                } else if (Test.mobileCards.get(s).getMoney() > 0.2) {
                                    Test.mobileCards.get(s).setRealFlow(Test.mobileCards.get(s).getRealFlow() + 1);
                                    Test.mobileCards.get(s).setMoney(Test.mobileCards.get(s).getMoney() - 0.1);
                                    Test.mobileCards.get(s).setConsumAmount(Test.mobileCards.get(s).getConsumAmount() + 0.1);
                                } else {
                                    System.out.println("此次使用了" + (i - 1) + "MB流量，继续使用请充值");
                                    if(i-1>0){
                                        Test.consumInfoList.add(new ConsumInfo(number, "上网", i - 1));
                                        Test.consumInfos.put(number, Test.consumInfoList);
                                    }else {
                                        try {
                                            throw new Exception();
                                        } catch (Exception e) {
                                            System.out.println("请先充值后使用！");
                                        }
                                    }
                                    break;
                                }
                                if (i == 1024) {
                                    Test.consumInfoList.add(new ConsumInfo(number, "上网", 1024));
                                    Test.consumInfos.put(number, Test.consumInfoList);
                                    System.out.println("和女朋友视频用了1GB流量。");
                                }
                            }
                            break;
                        case 1:
                            for (int i = 1; i <= 2048; i++) {
                                int temp = i;
                                if (((NetPackage) Test.mobileCards.get(s).getSerPackage()).getFlow() - Test.mobileCards.get(s).getRealFlow() >= 1) {
                                    Test.mobileCards.get(s).setRealFlow(Test.mobileCards.get(s).getRealFlow() + 1);
                                } else if (Test.mobileCards.get(s).getMoney() > 0.2) {
                                    Test.mobileCards.get(s).setRealFlow(Test.mobileCards.get(s).getRealFlow() + 1);
                                    Test.mobileCards.get(s).setMoney(Test.mobileCards.get(s).getMoney() - 0.1);
                                    Test.mobileCards.get(s).setConsumAmount(Test.mobileCards.get(s).getConsumAmount() + 0.1);
                                } else {
                                    System.out.println("此次使用了" + (i - 1) + "MB流量，继续使用请充值");
                                    if(i-1>0){
                                        Test.consumInfoList.add(new ConsumInfo(number, "上网", i - 1));
                                        Test.consumInfos.put(number, Test.consumInfoList);
                                    }else {
                                        try {
                                            throw new Exception();
                                        } catch (Exception e) {
                                            System.out.println("请先充值后使用！");
                                        }
                                    }
                                    break;
                                }
                                if (i == 2048) {
                                    Test.consumInfoList.add(new ConsumInfo(number, "上网", 2048));
                                    Test.consumInfos.put(number, Test.consumInfoList);
                                    System.out.println("看视频，不小心睡着，用了2GB流量。");
                                }
                            }
                            break;
                    }
                }
            }
        }
        Test.consumInfos.put(number, Test.consumInfoList);
        if (!index) {
            System.out.println("没有这张卡！");
        }
    }
}
